Skip to content

feat: add track Kiro CLI usage - #170

Merged
chattymin merged 2 commits into
chattymin:mainfrom
HyunTaek5:feat/add-kiro-cli-provider
Aug 16, 2026
Merged

chattymin merged 2 commits into
chattymin:mainfrom
HyunTaek5:feat/add-kiro-cli-provider

Conversation

@HyunTaek5

Copy link
Copy Markdown
Contributor

Summary

Kiro CLI stores conversation history locally in ~/Library/Application Support/kiro- cli/data.sqlite3, but no provider previously read it. This PR adds LocalKiroProvider to track Kiro CLI token usage and feed it into companion progression and usage tracking.

Key Implementation Details:

  • LocalKiroProvider Registration: Implemented on top of the shared additional-source cache and registered in UsageStore.init. Reports tokens only (reportsCost = false), as Kiro does not report per-token dollar costs.
  • Dual Schema Support: Handles both conversations_v2 (kiro-cli < 2.0.1, dedicated ID/timestamp columns) and conversations (kiro-cli 2.0.1+, directory-keyed with conversation_id inside JSON).
  • Cumulative Prompt Token Estimation:
    - Kiro lacks server-side sessions and resends the entire conversation history on every turn. Because user_prompt_length only records the immediate user input bytes, the reader accumulates user and assistant text lengths byte-by-byte (using a 4-bytes-per-token heuristic).
    - Seeded with latest_summary so post-compaction turns continue counting the history represented by the summary.
    - Base64 images blobs are excluded from byte counting to prevent token inflation.
    - Output tokens are estimated directly from actual streamed response bytes (response_size).
  • Cache Persistence for Cleared Sessions: Kiro deletes turns from its database on /clear or compaction. The .kiro cache merges each scan with previously-seen entries so tokens already counted during the app lifecycle are preserved.
  • Tests & Documentation: Added comprehensive unit tests in KiroUsageTests.swift (530 lines) and updated READMEs (EN/KO/JA).

Type of change

  • Bug fix
  • New feature
  • Refactor / cleanup
  • Documentation
  • Other:

UI changes

No direct changes under Sources/PokeTokenBar/UI/.

Checklist

  • swift build and swift test pass locally
  • PR title and description are written in English
  • UI changes are described above (before/after — images optional)
  • No copyrighted assets, secrets, or private tooling references are committed (see [CONTRIBUTING (../CONTRIBUTING.md))
  • Tests were added or updated for this change

Kiro CLI (a rebrand of aws/amazon-q-developer-cli) keeps its conversation
history locally in `~/Library/Application Support/kiro-cli/data.sqlite3`,
but no provider read it, so those tokens never reached the companion or
the usage tracker.

Add `LocalKiroProvider` on top of the shared additional-source cache and
register it in `UsageStore.init`.

Kiro's `RequestMetadata` (verified against its upstream source) never
persists a real token count:

- `user_prompt_length` is only the bytes of the message the user just
  typed (`conversation_state.user_input_message.content.len()` in the
  upstream Rust), not the full resent prompt. Kiro has no server-side
  session, so every turn resends the whole conversation — using this
  field as-is would undercount a long-running conversation by orders of
  magnitude.
- The reader instead accumulates each turn's `user`/`assistant` text
  byte-by-byte across the conversation (bytes/4 estimate), seeded with
  `latest_summary` so post-compaction turns still count the history a
  summary stands in for.
- `response_size` (accumulated from the real streamed response/tool-input
  bytes) has no such gap and is used as-is for output.

Two schema generations coexist and are both read: `conversations_v2`
(kiro-cli < 2.0.1, dedicated id/timestamp columns) and `conversations`
(2.0.1+, keyed by working directory, id embedded in the JSON).

Kiro also deletes turns from its database on `/clear` or compaction,
unlike every other local source here whose on-disk log only grows. The
`.kiro` cache case merges each scan with previously-seen entries instead
of replacing them, so a cleared conversation's already-counted tokens
stay counted for the rest of the app's process lifetime.

Tokens are a byte-based estimate with nothing more precise available
locally, so the provider reports tokens only (`reportsCost = false`),
same reasoning as Copilot.
Closes the one open item from issue chattymin#115's Definition of Done — a
store-level test asserting a new provider's snapshot reaches
today/week/month totals and burn tier, mirroring
testAggregatesTodayTokensAcrossProviders / testBurnTierCombinesProviders.
Parser/schema coverage for Kiro itself already lives in
KiroUsageTests.swift.
@chattymin
chattymin merged commit 3a2945d into chattymin:main Aug 16, 2026
2 checks passed
@chattymin

Copy link
Copy Markdown
Owner

Thank you for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants